package org.trebert.j2ee;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class OKServlet2 extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		PrintWriter out = response.getWriter();
		Enumeration en = request.getParameterNames();
		
		out.println("<html><head><title>ausgabe</title></head>");
		out.println("Hier ist OKServlet2<br />");
		out.println("getParameterNames()<br />");
		while (en.hasMoreElements()){
			String key = (String) en.nextElement();
			String value = (String) request.getParameter(key);
			out.println(key+"=>"+value);
		}
		
		out.println("<br />getParameterMap()<br />");
		Map<String, String[]> m = (Map<String, String[]>) request.getParameterMap();
		for (String key : m.keySet()){
			String[] values = (String[]) m.get(key); // Alle Werte zu einem Parameter
			if (values.length == 1){
				out.println(values[0] + "<br />");
			}else{
				out.print("[");
				for (String value : values){
					out.print(value + " ");
				}
				out.println("]<br />");				
			}
		}
		out.println("</body></html>");
	}	
}
